﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading.Tasks;

namespace Cherry.Agile.Framework.Cache
{
    /// <summary>
    /// 开放给用户的Cache接口，需要具体实现
    /// </summary>
    public interface ICache
    {
        bool Add(string key, object value);

        bool Add(string key, object value, DateTimeOffset absoluteExpiration);

        bool Add(string key, object value, TimeSpan slidingExpiration);

        bool Add(string key, object value, CachePolicy cachePolicy);


        bool Add(CacheKey cacheKey, object value, CachePolicy cachePolicy);


        object Get(string key);

        object GetOrAdd(string key, object value);


        object GetOrAdd(string key, object value, DateTimeOffset absoluteExpiration);

        object GetOrAdd(string key, object value, TimeSpan slidingExpiration);


        object GetOrAdd(string key, object value, CachePolicy cachePolicy);

        object GetOrAdd(CacheKey key, object value, CachePolicy cachePolicy);


        object GetOrAdd(string key, Func<string, object> valueFactory);

        object GetOrAdd(string key, Func<string, object> valueFactory, DateTimeOffset absoluteExpiration);

        object GetOrAdd(string key, Func<string, object> valueFactory, TimeSpan slidingExpiration);

        object GetOrAdd(string key, Func<string, object> valueFactory, CachePolicy cachePolicy);

        object GetOrAdd(CacheKey cacheKey, Func<CacheKey, object> valueFactory, CachePolicy cachePolicy);

        bool Contains(string key);
        
#if net45
        Task<object> GetOrAddAsync(CacheKey cacheKey, Func<CacheKey, Task<object>> valueFactory, CachePolicy cachePolicy);
#endif
        object Remove(string key);

        object Remove(CacheKey cacheKey);

        int Expire(CacheTag cacheTag);

        int Expire(string tag);


        void Set(string key, object value);

        void Set(string key, object value, DateTimeOffset absoluteExpiration);

        void Set(string key, object value, TimeSpan slidingExpiration);


        void Set(string key, object value, CachePolicy cachePolicy);

        void Set(CacheKey cacheKey, object value, CachePolicy cachePolicy);

    }
}
